{% for asset in page_obj %}
<tr id="asset-row-{{ asset.pk }}" data-asset-id="{{ asset.pk }}">
    <td>
        <input type="checkbox" class="form-check-input asset-checkbox" name="asset_ids" value="{{ asset.pk }}">
    </td>
    <td>
        {% if asset.ledger and asset.ledger.organization %}
            <span class="asset-badge-org" title="所属组织">
                <i class="fas fa-building me-1"></i>{{ asset.ledger.organization.name }}
            </span>
        {% else %}
            <span class="text-muted">-</span>
        {% endif %}
    </td>
    <td class="text-nowrap">
        {% if asset.asset_number %}
            <a href="{% url 'assets:asset_detail' asset.pk %}" class="asset-badge-number" title="查看资产详情" aria-label="资产编号 {{ asset.asset_number }}，查看详情">
                {{ asset.asset_number }}
            </a>
        {% else %}
            <span class="text-muted">-</span>
        {% endif %}
    </td>
    <td>
        <div class="d-flex align-items-center">
            <div>
                <span class="asset-name">{{ asset.name }}</span>
                {% if asset.description %}
                    <br><small class="text-muted" title="{{ asset.description }}">{{ asset.description|truncatechars:30 }}</small>
                {% endif %}
            </div>
        </div>
    </td>
    <td>
        {% if asset.category %}
            <span class="badge bg-secondary">{{ asset.category.name }}</span>
        {% else %}
            <span class="text-muted">-</span>
        {% endif %}
    </td>
    <td>
        {% if asset.status == 'idle' %}
            <span class="badge bg-success"><i class="fas fa-pause me-1"></i>闲置</span>
        {% elif asset.status == 'in_use' %}
            <span class="badge bg-primary"><i class="fas fa-user me-1"></i>在用</span>
        {% elif asset.status == 'borrowed' %}
            <span class="badge bg-info text-dark"><i class="fas fa-handshake me-1"></i>已借出</span>
        {% elif asset.status == 'maintenance' %}
            <span class="badge bg-warning text-dark"><i class="fas fa-wrench me-1"></i>维修中</span>
        {% elif asset.status == 'faulty' %}
            <span class="badge bg-danger"><i class="fas fa-exclamation-triangle me-1"></i>故障</span>
        {% elif asset.status == 'scrapped' %}
            <span class="badge bg-secondary"><i class="fas fa-times me-1"></i>已报废</span>
        {% else %}
            <span class="badge bg-secondary">{{ asset.get_status_display }}</span>
        {% endif %}
    </td>
    <td>
        {% if asset.department %}
            <div class="d-flex align-items-center">
                {{ asset.department.name }}
            </div>
        {% else %}
            <span class="text-muted">-</span>
        {% endif %}
    </td>
    <td>
        {% if asset.user %}
            <div class="d-flex align-items-center">
                <div class="user-info">
                    <strong title="{{ asset.user.get_full_name|default:asset.user.username }}">
                        {{ asset.user.get_full_name|default:asset.user.username }}
                    </strong>
                    {% if asset.user.profile.employee_id %}
                        <small class="text-muted">{{ asset.user.profile.employee_id }}</small>
                    {% endif %}
                </div>
            </div>
        {% else %}
            <span class="text-muted">未分配</span>
        {% endif %}
    </td>
    <td>
        {% if asset.purchase_price %}
            <span class="text-success fw-bold">¥{{ asset.purchase_price|floatformat:2 }}</span>
        {% else %}
            <span class="text-muted">-</span>
        {% endif %}
    </td>
    <td>
        {% if asset.purchase_date %}
            <div class="text-nowrap">
                {{ asset.purchase_date|date:"m-d" }}
            </div>
            <small class="text-muted">{{ asset.purchase_date|date:"Y" }}</small>
        {% else %}
            <span class="text-muted">-</span>
        {% endif %}
    </td>
    <td>
        <div class="btn-group btn-group-sm">
            <a href="{% url 'assets:asset_detail' asset.pk %}" class="btn btn-outline-info btn-icon" title="查看详情" aria-label="查看资产详情">
                <i class="fas fa-eye"></i>
            </a>
            <a href="{% url 'assets:asset_update' asset.pk %}" class="btn btn-outline-primary btn-icon" title="编辑" aria-label="编辑资产" data-modal="ajax" data-title="编辑资产">
                <i class="fas fa-edit"></i>
            </a>
            <div class="btn-group btn-group-sm action-dropdown">
                <button type="button" class="btn btn-outline-secondary dropdown-toggle btn-icon" data-bs-toggle="dropdown" title="更多操作">
                    <i class="fas fa-ellipsis-h" style="font-size:16px"></i>
                </button>
                <ul class="dropdown-menu dropdown-menu-end">
                    <li><a class="dropdown-item" href="{% url 'assets:asset_allocate' asset.pk %}" data-modal="ajax" data-title="分配资产">
                        <i class="fas fa-user-plus me-2"></i>分配
                    </a></li>
                    <li><a class="dropdown-item" href="{% url 'assets:asset_transfer' asset.pk %}" data-modal="ajax" data-title="资产调拨">
                        <i class="fas fa-exchange-alt me-2"></i>调拨
                    </a></li>
                    <li><a class="dropdown-item" href="{% url 'assets:asset_maintenance' asset.pk %}" data-modal="ajax" data-title="资产维修">
                        <i class="fas fa-wrench me-2"></i>维修
                    </a></li>
                    <li><a class="dropdown-item recycle-item" href="#" data-modal="confirm" data-post-url="{% url 'assets:asset_recycle' asset.pk %}" data-title="回收资产" data-message="确定要回收资产『{{ asset.name|escapejs }}{% if asset.asset_number %}（{{ asset.asset_number|escapejs }}）{% endif %}』吗？回收后：使用人将被清空，部门设置为空值，状态设为闲置">
                        <i class="fas fa-recycle me-2"></i>回收
                    </a></li>
                    <li><hr class="dropdown-divider"></li>
                    <li><a class="dropdown-item text-danger" href="#" data-modal="confirm" data-post-url="{% url 'assets:asset_delete' asset.pk %}" data-title="删除资产" data-message="确定要删除资产『{{ asset.name|escapejs }}』吗？此操作不可撤销！">
                        <i class="fas fa-trash me-2"></i>删除
                    </a></li>
                </ul>
            </div>
        </div>
    </td>
</tr>
{% empty %}
<tr>
    <td colspan="11" class="text-center py-4">
        <div class="text-muted">
            <i class="fas fa-boxes fa-2x mb-2"></i>
            <p class="mb-0">暂无资产数据</p>
        </div>
    </td>
</tr>
{% endfor %}
